package com.panda.web.controller.rests;

import java.util.List;
import java.util.Arrays;

import com.panda.common.core.domain.R;
import com.panda.web.service.rests.IAnnouncementService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.panda.web.utils.pageutils.PageResult;

import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.enums.BusinessType;
import com.panda.web.domain.dto.rests.AnnouncementDTO;
import com.panda.web.domain.vo.rests.AnnouncementVO;


/**
 * 公告
 * Controller
 *
 * @author cpanda
 * @date 2025-09-08
 */
@CrossOrigin
@RestController
@RequestMapping("/web/announcement")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class AnnouncementController extends BaseController {
    private final IAnnouncementService announcementService;

    /**
     * 查询公告
     * 列表
     */
    @GetMapping("/list")
    public PageResult<AnnouncementVO> List(AnnouncementDTO dto,
                                           @RequestParam("pageNum") Integer pageNum,
                                           @RequestParam("pageSize") Integer pageSize) {
        //返回分页信息
        PageResult<AnnouncementVO> voList = announcementService.PageList(dto, pageNum, pageSize);
        return voList;
    }


    /**
     * 查询公告
     * 列表 无分页
     */
    @GetMapping("/choiceList")
    public R choiceList(AnnouncementDTO dto) {
        List<AnnouncementVO> voList = announcementService.choiceList(dto);
        return R.ok(voList, "ok");
    }

    /**
     * 获取公告
     * 详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(announcementService.selectById(id));
    }

    /**
     * 删除公告
     */
    @Log(title = "公告 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(announcementService.removeByAnnouncementIds(Arrays.asList(ids)));
    }

    /**
     * 省市一体
     * @param addrs
     * @return
     */
    @GetMapping("/addrs")
    public R getAddre(ProAddrs addrs){
        List<ProAddrs> addrsList = announcementService.getAddre(addrs);
        return R.ok(addrsList,200,"ok");
    }


}
